package action;

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import bean.Meeting;
import biz.MeetingBiz;
import biz.impl.MeetingBizImpl;

public class MeetingAddAction extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.sendRedirect("login.jsp");
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		HttpSession session = request.getSession(false);
		if (session == null) {
			response.sendRedirect("login.jsp");
			return;
		}
		// 获取数据
		String topic = request.getParameter("topic");
		String participants = request.getParameter("participants");
		String mtype = request.getParameter("mtype");
		String guestname = request.getParameter("guestname");
		String depName = request.getParameter("depName");
		String mperson = request.getParameter("mperson");
		String meetingTime = request.getParameter("meetingTime");
		String completeTime = request.getParameter("completeTime");
		String content = request.getParameter("content");
		String precautions = request.getParameter("precautions");
		String remark = request.getParameter("remark");
		// 封装数据
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Meeting meeting = new Meeting();
		meeting.setTopic(topic);
		meeting.setParticipants(participants);
		meeting.setType(mtype);
		meeting.setGuestname(guestname);
		meeting.setDepartmentname(depName);
		meeting.setPerson(mperson);
		try {
			meeting.setMeetingdate(sdf.parse(meetingTime));
			meeting.setCompletetime(sdf.parse(completeTime));
		} catch (ParseException e) {
			e.printStackTrace();
		}
		meeting.setContent(content);
		meeting.setPrecautions(precautions);
		meeting.setRemark(remark);
		meeting.setMeetingstate("0");
		// 保存数据
		MeetingBiz mb = new MeetingBizImpl();
		boolean success = mb.save(meeting);
		if (success) {
			//response.getWriter().print("add meeting success");
			response.sendRedirect("meetingsearch.ac");
		} else {
			response.sendRedirect("add_meeting.jsp");
		}
	}

}
